<?php

namespace maotool\output;

use maotool\util\IdUtil;

/**
 * 控制台输出
 */
class Console
{

    public static function init()
    {
        $html = <<<EOD
<script>
    function setCookie(obj,time){
        let date = new Date(new Date().getTime()+ time*24*60*60*1000).toUTCString();
        for(let key in obj){
            document.cookie = key+"="+obj[key]+"; expires="+ date;
        }
    }
    function getCookie(key){
        return decodeURIComponent(document.cookie.match( new RegExp("(^|\\s)"+ key +"=([^;]+)(;|$)"))[2])
    }
    function removeCookie(key){
        setCookie({[key]: "" }, -1)
    }
    setInterval(function(){
        console.log(getCookie("maotool-console"));
    }, 1000);
</script>
EOD;
        echo $html;
    }

    public static function log()
    {
        setcookie("maotool-console", "浏览器关闭失效", time() + 30000);
    }

    public static function info()
    {

    }

    public static function error()
    {

    }

    public static function table()
    {

    }

}